<?php

namespace app\library\websocket\action;

use app\library\websocket\logic\Sessions;
use app\library\websocket\tool\MessageBuilder;

class History extends MessageCenter
{

	public function handle()
	{
		$history = Sessions::getMsgList($this->message->chat_id);
		$history = array_slice($history, $this->message->page, $this->message->limit);
		array_multisort(array_column($history, 'timestamp'), SORT_ASC, $history);
		$message = new MessageBuilder(false, $this->getAction());
		$message->write('获取成功', 200, ['history' => $history, 'page' => $this->message->page + 1]);
		$this->pusher->from($this->fd)->notice($message);
	}
}
